# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $


DESCRIPTION="The Swiss Army knife of DVD editing"
HOMEPAGE="http://www.videohelp.com/r0lZ/pgcedit/"
SRC_URI="http://www.videohelp.com/r0lZ/pgcedit/versions/PgcEdit_source_${PV}.zip"

RESTRICT="mirror"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="preview iso"

RDEPEND=">=dev-lang/tcl-8.4
	>=dev-lang/tk-8.4
	preview? ( app-emulation/wine )
	iso? ( app-cdr/cdrtools )"
DEPEND="${RDEPEND}"
src_unpack() {
	unpack ${A}
}

src_compile() {
	cd "${WORKDIR}"
	mv PgcEdit.tcl pgcedit || die "rename failed"
	# fix paths to look in /usr/share/pgcedit
	sed -i -e 's|"bin"|"../share/pgcedit/bin"|' pgcedit || die "sed failed"
	sed -i -e 's|"plugins"|"../share/pgcedit/plugins"|' pgcedit || die "sed failed"
	sed -i -e 's|config(apppath)/lib|config(apppath)/../share/pgcedit/lib|' pgcedit || die "sed failed"
	cd lib
	sed -i -e 's|lib/icons|../share/pgcedit/lib/icons|' toolbar.tcl || die "sed failed"
	for file in "blankcell.tcl menus.tcl streams.tcl trace.tcl utils.tcl";
	do
		sed -i -e 's|lib/data|../share/pgcedit/lib/data|' ${file}
	done
	cd ..
}

src_install() {
	cd "${WORKDIR}"
	dobin pgcedit
	dodir /usr/share/pgcedit
	dodir /usr/share/pgcedit/plugins
	keepdir /usr/share/pgcedit/plugins/
	insopts -m0755
	insinto /usr/share/pgcedit/bin
	doins bin/PgcEditPreview.exe bin/binversion.tcl
	dodir /usr/share/pgcedit/lib /usr/share/pgcedit/lib/icons /usr/share/pgcedit/lib/data /usr/share/pgcedit/lib/icons/sweetness
	insopts -m0644
	insinto /usr/share/pgcedit/lib
	doins lib/*
	insinto /usr/share/pgcedit/lib/icons
	doins lib/icons/*
	insinto /usr/share/pgcedit/lib/data
	doins lib/data/*
	insinto /usr/share/pgcedit/lib/icons/sweetness
	doins lib/icons/sweetness/*
	dodoc COPYING.txt HISTORY.txt TODO.txt
	insinto /usr/share/applications
	doins "${FILESDIR}/pgcedit.desktop"
	insinto /usr/share/pixmaps
	doins lib/icons/PgcEdit.ico
}
